package com.lgr.store.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lgr.store.service.SystemLogService;
import com.lgr.store.utils.ContextUtils;
import com.lgr.store.utils.PageObject;
import com.lgr.store.vo.SystemlogVo;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
@RequestMapping(value = "/admin/systemLog")
public class SystemLogController {
    @Resource
    private SystemLogService systemLogService;

    @RequestMapping(value = "/list")
    private String list(HttpServletRequest request,  SystemlogVo systemlogVo,PageObject pager, Model model) {
        if (systemlogVo.getEmpName()==null){
            //没有条件时从session取值
            if (request.getSession().getAttribute("systemlogVo") != null) {
                systemlogVo = (SystemlogVo) request.getSession().getAttribute("systemlogVo");
            }
        }else {
            request.getSession().setAttribute("systemlogVo",systemlogVo);
        }

        if (systemlogVo.getOptime()==null){
            systemlogVo.setOptime(ContextUtils.dateToStrShort(new Date()));
            systemlogVo.setOptime1(ContextUtils.dateToStrShort(new Date()));
        }
        if(systemlogVo.getOptime() != null && systemlogVo.getOptime().length()<11){
        	systemlogVo.setOptime(systemlogVo.getOptime() +" 00:00:00");
        }
        if(systemlogVo.getOptime1() != null && systemlogVo.getOptime1().length()<11){
        	systemlogVo.setOptime1(systemlogVo.getOptime1() +" 23:59:59");
        }
        
        pager.setTotalRows(systemLogService.getCount(systemlogVo));
        pager.setDatas(systemLogService.list(pager,systemlogVo));
        model.addAttribute("systemlogVo",systemlogVo);
        model.addAttribute("pager", pager);
        return "logList";
    }

    @RequestMapping(value = "/set")
    public String list() {
        return "set";
    }
}
